package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysDictType;
import com.xx.job.mapper.SysDictTypeMapper;
import com.xx.job.service.system.SysDictTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements SysDictTypeService {

    @Autowired
    private SysDictTypeMapper sysDictTypeMapper;


    @Override
    public int add(SysDictType sysDictType) {
        return sysDictTypeMapper.insert(sysDictType);
    }

    @Override
    public int delete(Long id) {
        return sysDictTypeMapper.deleteById(id);
    }

    @Override
    public int update(SysDictType sysDictType) {
        return sysDictTypeMapper.updateById(sysDictType);
    }

    @Override
    public SysDictType select(Long id) {
        return sysDictTypeMapper.selectById(id);
    }

    @Override
    public Map<String,Object> selectPageList(PageDTO pageDTO, SysDictType sysDictType) {
        Map<String,Object> data = new HashMap<>();
        IPage<SysDictType> page = new Page<>(pageDTO.getPageIndex(),pageDTO.getPageSize());
        QueryWrapper<SysDictType> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(sysDictType.getDictName())){
            wrapper.like("dict_name",sysDictType.getDictName().trim());
        }
        if(StringUtils.isNotBlank(sysDictType.getDictType())){
            wrapper.like("dict_type",sysDictType.getDictType().trim());
        }
        if(StringUtils.isNotBlank(sysDictType.getStatus())){
            wrapper.like("status",sysDictType.getStatus());
        }
        IPage<SysDictType> sysDictTypeIPage = sysDictTypeMapper.selectPage(page, wrapper);
        data.put("count",sysDictTypeIPage.getTotal());
        data.put("list",sysDictTypeIPage.getRecords());
        data.put("pageIndex",pageDTO.getPageIndex());
        data.put("pageSize", pageDTO.getPageSize());
        return data;
    }
}
